package com.tsll.controller;

import com.tsll.service.BorrowService;
import com.tsll.vo.BorrowVo;
import com.tsll.vo.RebackVo;
import com.tsll.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/borrow")
public class BorrowController {
    @Autowired
    private BorrowService borrowService;
//    图书归还信息
    @RequestMapping("/return")
    public Result getreturn(){
        return borrowService.getReturn();
    }
//    图书借阅信息
    @RequestMapping("/lend")
    public Result getlend(){
        return borrowService.getLend();
    }
//    借阅审核图书详情信息
    @RequestMapping("/details/{id}/{userId}")
    public  Result detail(@PathVariable Integer id,@PathVariable Integer userId){
        return borrowService.lendByIdAndByUserid(id,userId);
    }
//    审核通过更改借阅状态
    @RequestMapping("/access/{id}")
    public Result access(@PathVariable  Integer id){
        return borrowService.getAccess(id);
    }
//    审核失败更改驳回信息
    @RequestMapping("/reback")
    public Result reback(@RequestBody RebackVo rebackVo){
        return borrowService.updateBack(rebackVo);
    }

    //借阅图书
    @RequestMapping("/borrowBook")
    public  Result borrowBook(@RequestBody BorrowVo borrowVo){
            return borrowService.borrowBook(borrowVo);
    }

    //根据用户id查询用户借阅的书籍
    @RequestMapping("/borrowBooks/{id}")
    public  Result selectBorrowBooksById(@PathVariable  Integer id){
         return borrowService.borrowBooks(id);

    }
}
